//
//  DraggableAnnotationView.m
//  Tazama NGO
//
//  Created by jsheriff on 3/16/11.
//  Copyright 2011 The MITRE Corporation. All rights reserved.
//

#import "DraggableAnnotationView.h"


@implementation DraggableAnnotationView

- (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated {
    if (newDragState == MKAnnotationViewDragStateStarting) {
        // lift the pin and set the state to dragging
        CGPoint endPoint = CGPointMake(self.center.x, self.center.y - 20);
        [UIView animateWithDuration:0.2 animations:^{ self.center = endPoint; } completion:^(BOOL finished) { dragState = MKAnnotationViewDragStateDragging; }];
        self.dragState = MKAnnotationViewDragStateDragging;
    }
    else if (newDragState == MKAnnotationViewDragStateEnding)
    {
        // save the new location, drop the pin, and set state to none
        CGPoint endPoint = CGPointMake(self.center.x,self.center.y+20);
        [UIView animateWithDuration:0.2 animations:^{ self.center = endPoint; } completion:^(BOOL finished) { dragState = MKAnnotationViewDragStateNone; }];
        self.dragState = MKAnnotationViewDragStateNone;
    }
    else if (newDragState == MKAnnotationViewDragStateCanceling)
    {
        // drop the pin and set the state to none        
        CGPoint endPoint = CGPointMake(self.center.x,self.center.y+20);
        [UIView animateWithDuration:0.2 animations:^{ self.center = endPoint; } completion:^(BOOL finished) { dragState = MKAnnotationViewDragStateNone; }];
        self.dragState = MKAnnotationViewDragStateNone;
    }
    else if (newDragState == MKAnnotationViewDragStateDragging)
    {
        
    }
}

@end
